<template>
  <!-- 权限列表组件 -->
  <div class="authority-list">
    <!-- 头部路径导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 权限列表数据 -->
    <el-card class="box-card">
      <el-table :data="authorityList" stripe style="width: 100%" border>
        <el-table-column label="#" width="48" type="index"> </el-table-column>
        <el-table-column prop="authName" label="权限名称"> </el-table-column>
        <el-table-column prop="path" label="路径"> </el-table-column>
        <el-table-column label="权限等级">
          <template slot-scope="props">
            <el-tag v-if="props.row.level == 0" size="mini">一级</el-tag>
            <el-tag type="success" v-if="props.row.level == 1" size="mini">二级</el-tag>
            <el-tag type="warning" v-if="props.row.level == 2" size="mini">三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //权限列表数据
      authorityList: [],
      //加载层参数配置
      loadingConfig: {
        target: "body",
        fullscreen: true,
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.1)",
        text: "拼命加载中",
      },
    };
  },
  methods: {
    getAuthorityList(type) {
      //获取权限列表
      //打开加载层
      var loading = this.$loading.service(this.loadingConfig);
      //发起请求
      this.$axios
        .get("/rights/" + type)
        .then((res) => {
          if (res.meta.status == 200) {
            this.authorityList = res.data;
          }
        })
        .catch((error) => {
          this.$message.error(error);
        })
        .finally(() => {
          //关闭加载层
          this.$nextTick(() => {
            loading.close();
          });
        });
    },
  },
  mounted() {
    //模板加载完成后挂载数据
    this.getAuthorityList("list");
  },
};
</script>

<style lang="less">
table {
  td,
  th {
    font-size: 12px !important;
  }
}
</style>